<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../../js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM -->
    <script type="text/javascript" src="../../js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="../../js/babel.min.js"></script>
</head>

<body>
    <div id="root"></div>
    <!-- 注意：js的类型type="text/babel" -->
    <script type="text/babel">
        function Blog(props) {
            var sideBar = (
                <ul>
                    {props.posts.map((item) => {
                        return <li key={item.id}>{item.title}</li>
                    })}
                </ul>
            )
            var content = props.posts.map((item) =>
                <div key={item.id}>
                    <div>{item.title}</div>
                    <div>{item.content}</div>
                </div>
            )
            return (
                <div>
                    {sideBar}
                    <br />
                    {content}
                </div>
            )
        }

        const posts = [
            { id: 1, title: 'Hello World', content: 'Welcome to learning React!' },
            { id: 2, title: 'Installation', content: 'You can install React from npm.' }
        ];

        ReactDOM.render(
            <Blog posts={posts} />,
            document.getElementById('root')
        )
    </script>
</body>

</html>